#include "PMAbstractWindow.h"

namespace Proton 
{
	namespace Managers
	{

		PMAbstractWindow::PMAbstractWindow(void)
		{
		}


		PMAbstractWindow::~PMAbstractWindow(void)
		{
		}

		bool PMAbstractWindow::Create(unsigned int width, unsigned int height)
		{

			RECT wr = {0, 0, width, height};
			AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, false);

			hWnd = CreateWindowEx(NULL, className, windowName,
				WS_OVERLAPPEDWINDOW, 0, 0, wr.right - wr.left, wr.bottom - wr.top,
				NULL, NULL, hInstance, this);

			if (!hWnd) 
				return false;
			else 
				return true;
		}

		LRESULT CALLBACK PMAbstractWindow::msgRouter(HWND _hWnd, UINT message, WPARAM wParam, LPARAM lParam)
		{
			PMAbstractWindow *wnd = 0;

			if (message == WM_NCCREATE)
				::SetWindowLong(_hWnd, GWL_USERDATA, long((LPCREATESTRUCT(lParam))->lpCreateParams));

			wnd = (PMAbstractWindow*) (::GetWindowLong(_hWnd, GWL_USERDATA));

			if (wnd)
				wnd->wndProc(_hWnd, message, wParam, lParam);
			else
				return ::DefWindowProc(_hWnd, message, wParam, lParam);
		}
	}
}
